///*
// * To change this template, choose Tools | Templates
// * and open the template in the editor.
// */
//package company.folder.beans;
//
//import company.folder.abstraction.CompanyAdquiredProfileFilterer;
//import facades.CompanyAdquiredProfileFacade;
//import facades.CompanyFacade;
//import facades.CompanyFolderFacade;
//import facades.CountryFacade;
//import entities.Company;
//import entities.CompanyAdquiredProfile;
//import entities.CompanyFolder;
//import entities.Search;
//import javax.inject.Named;
//import java.io.Serializable;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.List;
//import javax.enterprise.context.SessionScoped;
//import javax.enterprise.event.Event;
//import javax.enterprise.event.Observes;
//import javax.inject.Inject;
//import company.folder.qualifiers.SeeAllProfilesEvent;
//import company.search.qualifiers.RecruitEvent;
//import entities.CompanyAdquiredProfileFolder;
//import facades.CompanyAdquiredProfileFolderFacade;
//import java.util.Locale;
//import java.util.ResourceBundle;
//import javax.faces.application.FacesMessage;
//import javax.faces.context.FacesContext;
//import qualifiers.ChosenEntityEvent;
//import qualifiers.CreatedEntityEvent;
//import qualifiers.EditedEntityEvent;
//import qualifiers.LoggedIn;
//import qualifiers.PreRemoveEntityEvent;
//import qualifiers.RemovedEntityEvent;
//
///**
// *
// * @author damfercer
// */
//@Named
//@SessionScoped
//public class ViewFolderBean extends CompanyAdquiredProfileFilterer implements Serializable {
//    @Inject
//    @LoggedIn
//    private Company company;
//    @Inject
//    CountryFacade countryFacade;
//    @Inject
//    CompanyFolderFacade folderEJB;
//    @Inject
//    CompanyAdquiredProfileFacade profileEJB;
//    @Inject
//    CompanyFacade companyFacade;
//    @Inject
//    CompanyAdquiredProfileFolderFacade companyAdquiredProfileFolderFacade;
//    @Inject
//    @EditedEntityEvent
//    private Event<CompanyAdquiredProfileFolder>editedCompanyAdquiredProfileFolder;
//    @Inject
//    @CreatedEntityEvent
//    private Event<CompanyAdquiredProfileFolder>createdCompanyAdquiredProfileFolder;
//    private CompanyFolder currentFolder;
//    private CompanyAdquiredProfile selectedAdquiredProfile;
//    private CompanyAdquiredProfileFolder companyAdquiredProfileFolder;
//    private Search selectedSearch;
//    @Inject
//    @ChosenEntityEvent
//    private Event<CompanyAdquiredProfile> selectCandidateEvent;
//    @Inject
//    @EditedEntityEvent
//    Event<CompanyFolder> editedFolderEvent;
//    @Inject
//    @PreRemoveEntityEvent
//    Event<CompanyAdquiredProfileFolder> preRemoveProfileFolderEvent;
//    @Inject
//    @RemovedEntityEvent
//    Event<CompanyAdquiredProfileFolder> removedProfileFolderEvent;
//    @Inject
//    @ChosenEntityEvent
//    private Event<CompanyFolder> selectedCompanyFolderEvent;
//    private CompanyFolder selectedFolder;
//    @Inject
//    @EditedEntityEvent
//    private Event<CompanyFolder> editedCompanyFolderEvent;
//    @Inject
//    private CompanyAdquiredProfileFacade companyAdquiredProfileFacade;
//
//    /**
//     * Creates a new instance of ViewFolderBean
//     */
//    public ViewFolderBean() {
//    }
//    
//    public void removeCompanyAdquiredProfileFolder(){
//        CompanyAdquiredProfileFolder companyAdquiredProfileFolder= companyAdquiredProfileFolderFacade.find(selectedAdquiredProfile, currentFolder);
//        if(companyAdquiredProfileFolder!=null){
//            preRemoveProfileFolderEvent.fire(companyAdquiredProfileFolder);
//            companyAdquiredProfileFolderFacade.remove(companyAdquiredProfileFolder);
//            removedProfileFolderEvent.fire(companyAdquiredProfileFolder);
//            currentFolder.getCompanyAdquiredProfileFolderList().remove(companyAdquiredProfileFolder);
//            editedFolderEvent.fire(currentFolder);
//            selectedAdquiredProfile.getCompanyAdquiredProfileFolderList().remove(companyAdquiredProfileFolder);
//            this.setFilteredProfiles(currentFolder.getCompanyAdquiredProfileList());
//            this.setSelectedAdquiredProfile(null);
//        }
//    }
//    
//    
//    public void onSelectedFolder(@Observes @ChosenEntityEvent CompanyFolder folder){
//        this.reinitFilter();
//        folderEJB.evict(folder,folder.getIdCompanyFolder());
//        this.currentFolder=folderEJB.find(folder.getIdCompanyFolder());
//        this.setSelectedAdquiredProfile(null);
//        this.selectedSearch=null;
//        if(currentFolder.getCompanyFolderType().getIdCompanyFolderType()==2){
//            this.setFilteredProfiles(getValidCompanyAdquiredProfileList(getCurrentFolder().getCompanyAdquiredProfileList()));
//        }
//        else{
//            this.setFilteredProfiles(currentFolder.getCompanyAdquiredProfileList());
//
//        }
//    }
//    
//    public void onViewAllProfiles(@Observes @SeeAllProfilesEvent Integer i){
//        this.reinitFilter();
//        this.currentFolder=null;
//        this.setSelectedAdquiredProfile(null);
//        this.selectedSearch=null;
//        this.setFilteredProfiles(getValidCompanyAdquiredProfileList());
//    }
//    
//    public void onRecruit(@Observes @RecruitEvent CompanyFolder folder){
//        this.reinitFilter();
//        folderEJB.evict(folder,folder.getIdCompanyFolder());
//        this.currentFolder=folder;
//        this.setSelectedAdquiredProfile(null);
//        this.selectedSearch=null;
//        this.setFilteredProfiles(currentFolder.getCompanyAdquiredProfileList());
//    }
//    
//    @Override
//    public void filter(){
//        //setFilteredProfiles(getCompanyAdquiredProfileFacade().getFilteredProfiles(getSqlGenerator().getSqlFromSearch(this.getSearch()),this.getCurrentFolder()));
//    }
//    
//    public void filterAllProfiles(){
//        //setFilteredProfiles(getCompanyAdquiredProfileFacade().getFilteredProfiles(getSqlGenerator().getSqlFromSearch(this.getSearch()), getCompany()));
//    }
//
//    public void setNewAdquiredProfileFolderState(){
//        editedFolderEvent.fire(currentFolder);
//        companyAdquiredProfileFolderFacade.edit(companyAdquiredProfileFolder);
//        editedCompanyAdquiredProfileFolder.fire(companyAdquiredProfileFolder);
//    }
//    
//    /**
//     * @return the currentFolder
//     */
//    public CompanyFolder getCurrentFolder() {
//        return currentFolder;
//    }
//
//    /**
//     * @param currentFolder the currentFolder to set
//     */
//    public void setCurrentFolder(CompanyFolder currentFolder) {
//        this.currentFolder = currentFolder;
//        this.setSelectedAdquiredProfile(null);
//        this.selectedSearch=null;
//    }
//
//    /**
//     * @return the selectedSearch
//     */
//    public Search getSelectedSearch() {
//        return selectedSearch;
//    }
//
//    /**
//     * @param selectedSearch the selectedSearch to set
//     */
//    public void setSelectedSearch(Search selectedSearch) {
//        this.selectedSearch = selectedSearch;
//    }
//
//    /**
//     * @return the selectedAdquiredProfile
//     */
//    public CompanyAdquiredProfile getSelectedAdquiredProfile() {
//        return selectedAdquiredProfile;
//    }
//
//    /**
//     * @param selectedAdquiredProfile the selectedAdquiredProfile to set
//     */
//    public void setSelectedAdquiredProfile(CompanyAdquiredProfile selectedAdquiredProfile) {
//        if(selectedAdquiredProfile!=null && currentFolder!=null){
//            companyAdquiredProfileFolder=companyAdquiredProfileFolderFacade.find(selectedAdquiredProfile, currentFolder);
//            for(CompanyAdquiredProfileFolder profAdquiFol: selectedAdquiredProfile.getCompanyAdquiredProfileFolderList()){
//                if(profAdquiFol.getCompanyFolder().equals(currentFolder))
//                    companyAdquiredProfileFolder=profAdquiFol;
//            }
//            //companyAdquiredProfileFolder=selectedAdquiredProfile.getCompanyAdquiredProfileFolderList()
//        }
//        this.selectedAdquiredProfile = selectedAdquiredProfile;
//    }
//    
//    public String selectFolder(CompanyFolder companyFolder){
//        selectedCompanyFolderEvent.fire(companyFolder);
//        return "/views/company/folder/ViewFolderView?faces-redirect=true";        
//    }
//    
//    public Integer dateDifference(Date compare){
//        Date now=new Date();
//        long diff=now.getTime()-compare.getTime();
//        long days=diff / 1000 / 60 / 60 / 24 / 365;
//        return (int)days;
//    }
//    
//    public void copyProfile(){
//        if(selectedFolder!=null){
//            companyAdquiredProfileFolder=companyAdquiredProfileFolderFacade.find(selectedAdquiredProfile, selectedFolder);
//        }
//        if(companyAdquiredProfileFolder==null && selectedFolder!=null){
//           companyAdquiredProfileFolder=createCompanyAdquiredProfileFolder(selectedAdquiredProfile);
//        }
//        setSelectedFolder(null);
//        //Mensaje de que se ha copiado de carpeta
//        FacesContext context=FacesContext.getCurrentInstance();
//        Locale locale=context.getViewRoot().getLocale();
//        ResourceBundle rb = ResourceBundle.getBundle("messages", locale);
//        String successMessage=rb.getString("CompanyAdquiredProfileCopied");
//        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, successMessage, successMessage);  
//        context.addMessage(null, message); 
//        context.renderResponse();
//    }
//    
//    public String seeProfile(){
//        selectCandidateEvent.fire(selectedAdquiredProfile);
//        return "/views/company/folder/ViewCandidateView?faces-redirect=true";
//    }
//        
//    public List<CompanyAdquiredProfile> getValidCompanyAdquiredProfileList(List<CompanyAdquiredProfile>list){
//        companyFacade.evict(company,company.getIdCompany());
//        List<CompanyAdquiredProfile> validCandidates=new ArrayList<CompanyAdquiredProfile>();
//        for (CompanyAdquiredProfile companyAdquiredProfile : list) {
//            if(companyAdquiredProfile.getCandidate().getBirthDay()!=null && companyAdquiredProfile.getCandidate().getBodyFormal()!=null && companyAdquiredProfile.getCandidate().getBustBlackWhite()!=null && companyAdquiredProfile.getCandidate().getBustColor()!=null && companyAdquiredProfile.getCandidate().getName()!=null && companyAdquiredProfile.getCandidate().getLastName()!=null && !validCandidates.contains(companyAdquiredProfile)){
//                validCandidates.add(companyAdquiredProfile);
//            }
//        }
//        return validCandidates;
//    }
//    
//    public List<CompanyAdquiredProfile> getValidCompanyAdquiredProfileList(){
//        return getValidCompanyAdquiredProfileList(getCompany().getCompanyAdquiredProfileList());
//    }
//        
//    
//  
//
//    /**
//     * @return the company
//     */
//    public Company getCompany() {
//        return company;
//    }
//
//    /**
//     * @param company the company to set
//     */
//    public void setCompany(Company company) {
//        this.company = company;
//    }
//
//    /**
//     * @return the companyAdquiredProfileFolder
//     */
//    public CompanyAdquiredProfileFolder getCompanyAdquiredProfileFolder() {
//        return  companyAdquiredProfileFolder;
//    }
//
//    /**
//     * @param companyAdquiredProfileFolder the companyAdquiredProfileFolder to set
//     */
//    public void setCompanyAdquiredProfileFolder(CompanyAdquiredProfileFolder companyAdquiredProfileFolder) {
//        companyAdquiredProfileFolderFacade.edit(companyAdquiredProfileFolder);
//        companyAdquiredProfileFolderFacade.evict(companyAdquiredProfileFolder, companyAdquiredProfileFolder.getIdCompanyAdquiredProfileFolder());
//        this.companyAdquiredProfileFolder = companyAdquiredProfileFolder;
//    }
//
//    /**
//     * @return the selectedFolder
//     */
//    public CompanyFolder getSelectedFolder() {
//        return selectedFolder;
//    }
//
//    /**
//     * @param selectedFolder the selectedFolder to set
//     */
//    public void setSelectedFolder(CompanyFolder selectedFolder) {
//        this.selectedFolder = selectedFolder;
//    }
//    
//    public CompanyAdquiredProfileFolder createCompanyAdquiredProfileFolder(CompanyAdquiredProfile profile){
//        CompanyAdquiredProfileFolder companyAdquiredProfileFldr=new CompanyAdquiredProfileFolder();
//        companyAdquiredProfileFldr.setCompanyAdquiredProfile(profile);
//        companyAdquiredProfileFldr.setCompanyFolder(selectedFolder);
//        companyAdquiredProfileFldr.setCreationDate(new Date());
//        companyAdquiredProfileFolderFacade.create(companyAdquiredProfileFldr);
//        createdCompanyAdquiredProfileFolder.fire(companyAdquiredProfileFldr);
//        selectedFolder.getCompanyAdquiredProfileList().add(profile);
//        editedCompanyFolderEvent.fire(selectedFolder);
//        selectedAdquiredProfile.getCompanyAdquiredProfileFolderList().add(companyAdquiredProfileFldr);
//        companyAdquiredProfileFacade.edit(selectedAdquiredProfile);
//        return companyAdquiredProfileFldr;
//    }
//
//}
